<table border="1" cellpadding="2" cellspacing="2">
    <tr style="background-color: #376BAD; font-weight: bold; color: #FFFFFF">
        <td width="10px">Action</td>
        <!-- header table -->    
        <?php
        if ($TotalBarang) {
            $arrCount = mysql_num_fields($TotalBarang);
            for ($colCounter = 0; $colCounter <= $arrCount - 1; $colCounter++) {
                $field_info = mysql_fetch_field($TotalBarang, $colCounter);
                $columnName = $field_info->name;
                // pengaturan style utk kolom tertentu
                $vStyle = '';
                // kolom keterangan, perlakuan khusus (hidden)
                if (strtoupper($columnName) == 'KETERANGAN') {
                    $rowAllBarang = mysql_fetch_array($TotalBarang);
                    $longRemark = $rowAllBarang[$colCounter];
                    if (strlen($longRemark) > 50) {
                        $vStyle = 'style="display: none;"';
                    }
                }
                // kolom rownum dan id, perlakuan khusus juga
                if ((strtoupper($columnName) == 'ROWNUM') or (strtoupper($columnName) == 'ID')) {
                    $vStyle = 'style="width: 15px"';
                    if (strtoupper($columnName) == 'ROWNUM') {
                        $columnName = 'No';
                    }
                }
                ?>
                <td <?php echo $vStyle ?>><?php echo ucfirst($columnName) ?></td>
                <?php
            }
        }
        ?>
    </tr>
    <!-- body table -->    
    <?php
    $maxRowPerPage = 5;
    $maxRow = 1; // jumlah loop
    $nPage = 1; // initial halaman
    if (isset($_SESSION['curPage'])) {
        $nPage = $_SESSION['curPage'];
    }
    $nTotPage = 1;
    $arrCount = 1; // initial column count
    if ($resAllBarang) {
        // hitung jumlah loop
        if ($TotalRow < $maxRowPerPage) {
            $maxRow = $TotalRow;
        } else {
            $maxRow = $maxRowPerPage;
        }
        // hitung jumlah halaman
        $nCekPage = $TotalRow % $maxRowPerPage;
        if ($nCekPage == 0) {
            $nTotPage = $TotalRow / $maxRowPerPage;
        } else {
            $nTotPage = (($TotalRow - $nCekPage) / $maxRowPerPage) + 1;
        }
        $remark = ''; // keterangan yg panjang
        $remarkLength = 0; // panjang keterangan
        $arrCount = 0; // jumlah kolom
        for ($rowCounter = 1; $rowCounter <= $maxRow; $rowCounter++) {
            $rowAllBarang = mysql_fetch_array($resAllBarang);
        //while ($rowAllBarang = mysql_fetch_row($resAllBarang)) {
            ?>
            <tr valign="top" style="background-color: #C8D7EB">
                <td>
                    <button type="button" onclick="fnUpdate(<?php echo $rowAllBarang[1] ?>)" style="width: 60px; text-align: center" name="btUpdate" id="btUpdate">Update</button>
                    <br>
                    <button type="button" onclick="fnDelete(<?php echo $rowAllBarang[1] ?>)" style="width: 60px; text-align: center" name="btHapus" id="btHapus">Hapus</button>
                </td>
                <?php
                $arrCount = mysql_num_fields($resAllBarang);
                for ($counter = 0; $counter <= $arrCount - 1; $counter++) {
                    // kolom keterangan, perlakuan khusus (hidden)
                    $field_info = mysql_fetch_field($resAllBarang, $counter);
                    $columnName = $field_info->name;
                    $vStyle = '';
                    if (strtoupper($columnName) == 'KETERANGAN') {
                        $remark = $rowAllBarang[$counter];
                        $remarkLength = strlen($longRemark);
                        if ($remarkLength > 50) {
                            $vStyle = 'style="display: none"';
                        }
                    }
                    ?>
                    <td align="left" <?php echo $vStyle ?>><?php echo $rowAllBarang[$counter] ?></td>
                    <?php
                }
                ?>
            </tr>
            <?php
            if ($remarkLength > 50) {
            ?>
            <tr>
                <td colspan="<?php echo $arrCount ?>">
                    <?php echo $remark ?>
                </td>
            </tr>
            <?php
            }
            $nCounter = $rowAllBarang[0];
            if ($nCounter == $TotalRow) {
                break;
            }
        }
        ?>
        <tr>
            <td colspan="<?php echo $arrCount+1 ?>">
                <button type="button" onclick="fnFirstCatalog()" name="btFirst" id="btFirst">First</button>
                <button type="button" onclick="fnPrevCatalog()" name="btPrev" id="btPrev">Prev</button>

                <input type="text" name="txtCurPage" id="txtCurPage" size="2" value="<?php echo $nPage ?>">
                <input type="text" name="txtTotalPage" id="txtTotalPage" size="2" value="<?php echo $nTotPage ?>">
                <input type="text" name="txtRecordPerPage" id="txtRecordPerPage" size="2" value="<?php echo $maxRow ?>">
                <input type="text" name="txtTotalRow" id="txtTotalRow" size="2" value="<?php echo $TotalRow ?>">
                <input type="text" name="txtUpdate" id="txtUpdate" size="2" value="<?php echo $kodeUbah ?>">
                <input type="text" name="txtUpdateID" id="txtUpdateID" size="2" value="<?php echo $idBarang ?>">
                
                <button type="button" onclick="fnNextCatalog()" name="btNext" id="btNext">Next</button>
                <button type="button" onclick="fnLastCatalog()" name="btLast" id="btLast">Last</button>
            </td>
        </tr>
        <?php
    }
    ?>
</table>